//
//  StepBaseViewController.m
//  BiologyLibrary
//
//  Created by 朱进 on 16/7/16.
//  Copyright © 2016年 youxh. All rights reserved.
//

#import "StepBaseViewController.h"
#import "RecordFirstViewController.h"

@implementation StepBaseViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    

    if (!self.fromtype) {
        // 创建一个自定义的按钮，并添加到导航条右侧。
//        UIButton*_btnNaviRight = [CustomNaviBarView createImgNaviBarBtnByImgNormal:@"nav_more"
//                                                                      imgHighlight:@"nav_more"
//                                                                            target:self
//                                                                            action:@selector(changeRecord)];
//        [self setNaviBarRightBtn:_btnNaviRight];
    }
}


#pragma makr - UserAction
- (void) changeRecord {
    
    if (_changeRecordView == nil) {
        _changeRecordView = [[ChangeRecordView alloc] initWithFrame:self.view.bounds
                                                               type:self.record.type
                                                           recordId:self.record.recordId];
        _changeRecordView.backgroundColor = [UIColor clearColor];
        _changeRecordView.delegate = self;
        [_changeRecordView addTarget:self action:@selector(hide)
                    forControlEvents:UIControlEventTouchDown];
    }
    
    [[[UIApplication sharedApplication] keyWindow] addSubview:_changeRecordView];
}

- (void) hide {
    
    [_changeRecordView removeFromSuperview];
}

#pragma ChangeRecordDelegate
- (void) changeRecordView:(ChangeRecordView *)changeRecordView didSelecredRecord:(Record *)record {
    
    [self hide];
    
    NSArray *vcArray = [self.navigationController viewControllers];
    if ([vcArray count] > 1 &&
        [[vcArray objectAtIndex:1] isKindOfClass:[RecordFirstViewController class]]) {
        
        RecordFirstViewController *recordFirstVC = [vcArray objectAtIndex:1];
        
        [self.navigationController popToViewController:recordFirstVC animated:NO];
        
        [recordFirstVC gotoSelectedRecord:record];
    }
}

@end
